package com.job.zhangqiyan;

import java.util.Scanner;

/**
 * @author zhangqiyan
 * @version 1.0
 * @since 2022-07-05 06:01:31
 */
public class Man {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("你要玩游戏的人数：");
        int n=sc.nextInt();
        int victoryNumber=Man.getVictoryNumber(n);
        System.out.println("最后剩下："+victoryNumber);
    }
    public static int getVictoryNumber(int n){
        int[] persons=new int[n];
        for(int i=0;i<persons.length;i++){
            persons[i]=i+1;
        }
        while (persons.length>3){
            int[] newPersons=new int[persons.length-1];
            for(int i=3;i<persons.length;i++){
                newPersons[i-3]=persons[i];
            }
            newPersons[newPersons.length-2]=persons[0];
            newPersons[newPersons.length-1]=persons[1];
            persons=newPersons;
        }
        return persons[1];
    }
}